﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Specialized;

using Husb.Util;
using Husb.Util.Enum;
using CentralOffice.Task.Data;
using CentralOffice.Task.BusinessActions;

using ApplicationTable = CentralOffice.Task.Data.ApplicationDataSet.ApplicationsDataTable;
using ApplicationRow = CentralOffice.Task.Data.ApplicationDataSet.ApplicationsRow;

using ApprovalTable = CentralOffice.Task.Data.ApprovalDataSet.ApprovalsDataTable;
using ApprovalRow = CentralOffice.Task.Data.ApprovalDataSet.ApprovalsRow;

using CentralOffice.MyTable.Data;
using CentralOffice.MyTable.BusinessActions;
using Husb.Security;
using CentralOffice.Admin.BusinessActions;

using SmsTable = CentralOffice.MyTable.Data.SmsDataSet.smsDataTable;
using SmsRow = CentralOffice.MyTable.Data.SmsDataSet.smsRow;
using SmsBodyTable = CentralOffice.MyTable.Data.SmsDataSet.sms_bodyDataTable;
using SmsBodyRow = CentralOffice.MyTable.Data.SmsDataSet.sms_bodyRow;
using System.Collections;
using System.Data;

namespace CentralOffice.WebClient.Tasks
{
    public partial class ApplicationExecutor : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                SiteUtil.PopulateListBox(ddlCategory, SiteConstants.ApprovalObject, true);
                ddlCategory.SelectedIndex = 0;
                
            }
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            gv.PageIndex = 0;

            ApplicationRow application = (new ApplicationDataSet()).Applications.NewApplicationsRow();

            application.Name = txtName.Text;
            if (ddlCategory.SelectedIndex > 0)
            {
                application.Category = Int32.Parse(ddlCategory.SelectedItem.Value);
            }
            application.Applicant = txtApplicant.Text;

            if (txtDateOfApplication.Text.Length > 0)
            {
                application.DateOfApplication = DateTime.Parse(txtDateOfApplication.Text);
            }
            if (txtDateOfApplicationEnd.Text.Length > 0)
            {
                application.DateOfApplicationEnd = DateTime.Parse(txtDateOfApplicationEnd.Text);
            }
            
            odsApplication.SelectParameters.Clear();
            odsApplication.SelectParameters.Add("whereClause", application.FilterExpression);
        }


        protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ApplicationRow row = (e.Row.DataItem as DataRowView).Row as ApplicationRow;
                if (!row.IsApplicationCreatedByNull() && row.ApplicationCreatedBy != row.Applicant)
                {
                    //e.Row.Style.Add(HtmlTextWriterStyle.Color, "#483D8B");
                    foreach (TableCell cell in e.Row.Cells)
                    {
                        cell.Style.Add(HtmlTextWriterStyle.Color, "#483D8B");
                    }
                }

                TableCell statusCell = e.Row.Cells[6];
                if (statusCell.Text == "在审")
                {
                    statusCell.Style.Add(HtmlTextWriterStyle.Color, SiteUtil.GetExceptionalDataColor());
                }
                else if (statusCell.Text == "通过")
                {
                    statusCell.Style.Add(HtmlTextWriterStyle.Color, "#0f0");
                }
                else if (statusCell.Text == "否决")
                {
                    statusCell.Style.Add(HtmlTextWriterStyle.Color, "#f00");
                }
                else if (statusCell.Text == "已执行")
                {
                    statusCell.Style.Add(HtmlTextWriterStyle.Color, "#6f0");
                }
            }
        }
    }
}
